/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * @format
 * @flow
 */

import React, {
  Component,
} from "react";
import {
  View,
  StatusBar,
} from 'react-native';
import {
  createAppContainer,
} from 'react-navigation';
import Toast, {
  DURATION,
} from 'react-native-easy-toast'

import {
  setTopLevelNavigator,
} from "./src/navigation";
import router from "./src/router-config";

import Loading from './src/components/loading/loading';
import onfire from './src/model/onfire';

const AppContainer = createAppContainer(router);

let self;
global.showLoading = () => {};
global.closeLoading = () => {};
global.showToast = () => {};
global.onfire = onfire;

export default function App() {
  self = this;
  global.showLoading = function() {
    self.Loading.show();
  };
  global.closeLoading = function() {
    self.Loading.close();
  };

  global.showToast = function(content, cb = null) {
    if (typeof content !== 'string') {
      content = content.toString();
    }
    self.Toast.show(content, 500, cb);
  };

  return (
    <View style={{flex: 1}}>
      <StatusBar
        backgroundColor='#f6db7b'
      />
      <AppContainer ref={navigatorRef => {
        setTopLevelNavigator(navigatorRef);
      }} />
      <Loading ref={r=>{this.Loading = r}} hide={true} />
      <Toast position='top' ref={r=>{this.Toast = r}}/>
    </View>
  );
}